package com.hjqjl.whdemo.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;

import com.hjqjl.whdemo.databinding.DialogCustomBinding;

public class DialogCustom extends Dialog {
    private Context context;
    private final String title;
    private final String msg;
    private final OnClickMyListener listener;

    public static DialogCustom show(Context context, String title, String msg, OnClickMyListener listener) {
        DialogCustom dialogTop = new DialogCustom(context, title, msg, listener);
        dialogTop.show();
        return dialogTop;
    }

    public DialogCustom(@NonNull Context context, String title, String msg, OnClickMyListener listener) {
        super(context);
        this.context = context;
        this.title = title;
        this.msg = msg;
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        DialogCustomBinding binding = DialogCustomBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.tvTitle.setText(title);
        binding.tvMessage.setText(msg);
        binding.tvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onMyClick(DialogCustom.this);
                }
            }
        });
    }

    public interface OnClickMyListener {
        void onMyClick(Dialog dialog);
    }
}
